package Algorithm.handleString.swordOffer;

/**
 * 剑指 Offer 05. 替换空格 https://leetcode.cn/problems/ti-huan-kong-ge-lcof
 */
public class ReplaceSpace {

    public String replaceSpace(String s) {
        //替换字符串中所有指定字符串：1.replace()可替换字符或字符串 2.replaceAll()可替换字符串或匹配正则表达式替换
        return s.replace(" ", "%20");
    }

    public String replaceSpace2(String s) {
        StringBuilder res = new StringBuilder();
        for(Character c : s.toCharArray())
        {
            if(c == ' ') res.append("%20");
            else res.append(c);
        }
        return res.toString();
    }

}
